<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="">
    <title></title>
    <% include("../inc/list_css.html"){}%>
</head>
<body>
<div class="ibox ">
    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-md-12">

                    <table data-toggle="table " id="table" data-show-export="true" class=" table-striped table-no-bordered fixed-table-container table-row-border-color table-hovered table-hover">
                        <thead class="table-header">
                        <tr>
                            <th data-field="name">接口名称</th>
                            <th data-field="system_name">所属系统</th>
                            <th data-field="createDate">创建时间</th>
                            <th data-field="head" data-formatter="checkedFormatter">是否选中</th>
                            <th data-field="head" data-formatter="copyFormatter">复制接口地址</th>
                        </tr>
                        </thead>
                    </table>

                </div>
            </div>
        </div>
    </div>
</div>


<% include("../inc/list_js.html"){}%>
<script>

    function checkedFormatter(value, row, index) {
        var html='';
        if(row.status=='true'){
            html += '<input class="ischecked"  name="checked" id="'+row.id+'" type="checkbox" checked />';
        }else{
            html += '<input class="ischecked"  name="checked" id="'+row.id+'" type="checkbox" />';
        }
        return html;
    }

    function copyFormatter(value, row, inde) {
        var html='';
        html += '<a href="javascript:void(0)" class="icon-copy-link hive_icon color_normal" onclick="copyToClipboard(\''+row.url+'\'+\'/\'+\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="复制id"></a>';
        html += '<textarea id=\''+row.url+'/'+row.id+'\' style="display: none;" value=\''+row.url+'/'+row.id+'\'>'+row.url+'/'+row.id+'</textarea>';
        return html;

    }

    function copyToClipboard(elementId) {
        // 创建元素用于复制
        var aux = document.createElement("input");

        // 获取复制内容
        var content = document.getElementById(elementId).innerHTML || document.getElementById(elementId).value;

        // 设置元素内容
        aux.setAttribute("value", content);

        // 将元素插入页面进行调用
        document.body.appendChild(aux);

        // 复制内容
        aux.select();

        // 将内容复制到剪贴板
        document.execCommand("copy");

        // 删除创建元素
        document.body.removeChild(aux);
        parent.layer.msg("复制成功!")
    }



    $(document).on("click",".ischecked",function () {
        if($(this).is(':checked')){
            $(this).attr("value",'1');//选中
        }else{
            $(this).attr("value",'0');//非选中
        }
        var ischecked=$(this).attr("value");//1.选中,0非选中
        var interface_id=$(this).attr("id");//接口id

        if(ischecked=='1'){
            $.ajax({
                url: "/sys/thirdinterface/save",
                type: 'GET',
                data:{
                    "ischecked":ischecked,
                    "third_party_id": "${third_party_id!}",
                    "interface_id":interface_id

                },
                success: function(data){
                    if (data.state=="ok" == false){
                        layer.msg(data.info);
                    }
                }});
        }else if(ischecked=='0'){
            $.ajax({
                url: "/sys/thirdinterface/delete",
                type: 'GET',
                data:{
                    "ischecked":ischecked,
                    "third_party_id": "${third_party_id!}",
                    "interface_id":interface_id

                },
                success: function(data){
                    if (data.state=="ok" == false){
                        layer.msg(data.info);
                    }
                }});
        }


    });
    /**
     * 加载页面数据
     * */
    (function () {

        $('#table').bootstrapTable({
            url: "ajaxlist?third_party_id=${third_party_id!}",
            dataType: 'json',
            contentType: 'application/json',
            search: true,
            searchAlign: 'right',
            pagination: true,
            showRefresh: true,
            pageSize: 20,
            showToggle: false,//是否显示card/table切换按钮
            showColumns: true,//是否显示内容列下拉框
            pageList: [20, 50, 100],
            iconSize: 'outline',
            toolbar: '#eventsToolbar',
            paginationHAlign: 'right', //right, left
            paginationVAlign: 'bottom',
            icons: {
                refresh: 'icon-refresh',
                toggle: 'glyphicon-list-alt',
                columns: 'icon-select',
                export: 'icon-export'
            },
            responseHandler: function (res) {
                $("#dsh").html(res.length);
                return res;
            },
            formatNoMatches: function () { //判断有无数据
                var imghtml = '<div class="flexed_column content_center content_alignCenter padding-20"><img src="https://static.9hive.cn/global/img/nodata.png" class="no_data"/><span class="font-size-16">暂无数据</span></div>';
                return imghtml;
            },
            formatLoadingMessage: function () {  //数据加载中样式
                return ' <div id="loading"><div id="loading-center">' +
                    '<div id="loading-center-absolute"><div class="object" id="object_one">' +
                    '</div><div class="object" id="object_two"></div><div class="object" id="object_three">' +
                    '</div><div class="object" id="object_four"></div></div></div>努力加载中...</div>'
            },
        });

        $('#add').on('click', function (e) {
            location.href = 'add';
        });

        $(".wrapper").tooltip({selector: "[data-toggle=tooltip]", container: "body"});

    })();
</script>
</body>
</html>